//
//  HSLiveListCell.m
//  HolyShit
//
//  Created by Robin on 2017/3/30.
//  Copyright © 2017年 HolyShit. All rights reserved.
//

#import "HSLiveListCell.h"

@interface HSLiveListCell ()

@property (nonatomic, strong) UILabel *leftTimeLb;
@property (nonatomic, strong) UILabel *leftNameLb;
@property (nonatomic, strong) UILabel *midTopLb;
@property (nonatomic, strong) UILabel *midBottomLb;
@property (nonatomic, strong) UILabel *rightNameLb;
@property (nonatomic, strong) UILabel *rightTimeLb;
@property (nonatomic, strong) NSDateFormatter *format;
@property (nonatomic, strong) UIImageView *leftIcon;
@property (nonatomic, strong) UIImageView *rightIcon;

@end

@implementation HSLiveListCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self commonInit];
    }
    return self;
}

- (void)commonInit
{
    [self my_setSelectedBg];
    self.backgroundColor = WHITE_COLOR;
    self.width = ScreenWidth;
    [self addSubview:self.leftTimeLb];
    [self.leftTimeLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.mas_equalTo(0);
        make.left.mas_equalTo(1);
        make.width.mas_equalTo(40);
    }];
    
    [self addSubview:self.leftIcon];
    [self.leftIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(10);
        make.centerX.equalTo(self.leftTimeLb.mas_right).offset(ScreenWidth * 0.25 / 2);
        make.width.height.mas_equalTo(35);
    }];
    
    [self addSubview:self.leftNameLb];
    [self.leftNameLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.leftIcon.mas_bottom).offset(5);
        make.left.equalTo(self.leftTimeLb.mas_right);
        make.width.mas_equalTo(ScreenWidth * 0.25);
        //        make.bottom.mas_greaterThanOrEqualTo(10);
    }];
    
    [self addSubview:self.rightTimeLb];
    [self.rightTimeLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.mas_equalTo(0);
        make.right.mas_equalTo(-1);
        make.width.equalTo(self.leftTimeLb);
    }];
    [self addSubview:self.rightIcon];
    [self.rightIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.width.height.equalTo(self.leftIcon);
        make.centerX.equalTo(self.rightTimeLb.mas_left).offset(-ScreenWidth * 0.25 / 2);
    }];
    [self addSubview:self.rightNameLb];
    [self.rightNameLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.width.equalTo(self.leftNameLb);
        make.right.equalTo(self.rightTimeLb.mas_left);
        //        make.bottom.mas_greaterThanOrEqualTo(10);
    }];
    
    [self addSubview:self.midTopLb];
    [self.midTopLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.mas_centerX);
        make.left.equalTo(self.leftNameLb.mas_right).offset(2);
        make.right.equalTo(self.rightNameLb.mas_left).offset(-2);
        make.bottom.equalTo(self.mas_bottom).multipliedBy(0.6);
        //        make.top.mas_greaterThanOrEqualTo(10);
        //        make.width.mas_equalTo(ScreenWidth * 0.35);
    }];
    
    [self addSubview:self.midBottomLb];
    [self.midBottomLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.midTopLb.mas_centerX);
        make.top.equalTo(self.midTopLb.mas_bottom);
        //        make.bottom.greaterThanOrEqualTo(self.mas_bottom).offset(-10);
    }];
    
    
}

- (void)setModel:(HSLiveModel *)model
{
    _model = model;
    self.leftTimeLb.text = model.time;
    self.leftNameLb.text = model.visit_team.length > 0  ? model.visit_team : @"客队";
    self.midTopLb.text = model.league.name_cn;
    self.midBottomLb.text = model.keywords;
    self.rightNameLb.text = model.home_team.length > 0 ? model.home_team : @"主队";
    [self.leftIcon my_setImage:[NSString stringWithFormat:@"http://duihui.oss-cn-hangzhou.aliyuncs.com/zuqiu/%@.png",model.visit_logo]];
    [self.rightIcon my_setImage:[NSString stringWithFormat:@"http://duihui.oss-cn-hangzhou.aliyuncs.com/zuqiu/%@.png",model.home_logo]];
    
    NSDate *date = [self.format dateFromString:model.start];;
    NSDate *now = [NSDate date];
    if (date.timeIntervalSince1970 > now.timeIntervalSince1970) {
        self.rightTimeLb.text = @"未开始";
    }
    else{
        self.rightTimeLb.text = @"进行中";
    }
}

- (UILabel *)leftTimeLb{
    if(!_leftTimeLb){
        _leftTimeLb = [UILabel labelWithFont:MYFont(Font24) color:HEXCOLOR(HSColorBlack)];
    }
    return _leftTimeLb;
}

- (UILabel *)leftNameLb{
    if(!_leftNameLb){
        _leftNameLb = [UILabel labelWithFont:MYFont(Font26) color:HEXCOLOR(HSColorBlack)];
        _leftNameLb.numberOfLines = 0;
        _leftNameLb.textAlignment = NSTextAlignmentCenter;
    }
    return _leftNameLb;
}

- (UILabel *)midTopLb{
    if(!_midTopLb){
        _midTopLb = [UILabel labelWithFont:MYFont(Font28) color:HEXCOLOR(HSColorBlack)];
        _midTopLb.numberOfLines = 0;
        _midTopLb.textAlignment = NSTextAlignmentCenter;
    }
    return _midTopLb;
}

- (UILabel *)midBottomLb{
    if(!_midBottomLb){
        _midBottomLb = [UILabel labelWithFont:MYFont(11) color:HEXCOLOR(HSColorGray)];
        _midBottomLb.numberOfLines = 0;
    }
    return _midBottomLb;
}

- (UILabel *)rightNameLb{
    if(!_rightNameLb){
        _rightNameLb = [UILabel labelWithFont:MYFont(Font26) color:HEXCOLOR(HSColorBlack)];
        _rightNameLb.numberOfLines = 0;
        _rightNameLb.textAlignment = NSTextAlignmentCenter;
    }
    return _rightNameLb;
}

- (UILabel *)rightTimeLb{
    if(!_rightTimeLb){
        _rightTimeLb = [UILabel labelWithFont:MYFont(Font24) color:HEXCOLOR(HSColorGray)];
    }
    return _rightTimeLb;
}

- (NSDateFormatter *)format{
    if(!_format){
        _format = [[NSDateFormatter alloc] init];
        [_format setDateFormat:@"yyyy-MM-dd HH:mm"];
    }
    return _format;
}

- (UIImageView *)leftIcon
{
    if (!_leftIcon) {
        _leftIcon = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 35, 35) imageType:MYImageTypeSmallPic];
        _leftIcon.placeholderImageName = _leftIcon.failureImageName = @"kedui";
    }
    return _leftIcon;
}

- (UIImageView *)rightIcon
{
    if (!_rightIcon) {
        _rightIcon = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 35, 35) imageType:MYImageTypeSmallPic];
        _rightIcon.placeholderImageName = _rightIcon.failureImageName = @"zhudui";
    }
    return _rightIcon;
}

@end
